package com.itheima.homework.one;
/*
* - 需求：使用tcp通信，完成文件上传案例


 * */

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception {

        //建立通道
        Socket socket = new Socket("localhost",10086);

        OutputStream o1 = socket.getOutputStream();
        BufferedOutputStream b1 = new BufferedOutputStream(o1);

        File file = new File("C:\\Users\\Administrator\\Desktop\\zzzz.txt");
        Byte[] b = new Byte[1024];

        String name = file.getName();

        b1.write(name.getBytes());

        b1.flush();

        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));

        byte[] bytes = new byte[1024];
        int len;

        while ((len = bufferedInputStream.read(bytes)) != -1) {
            b1.write(bytes,0,len);

        }

        b1.close();

        socket.close();


    }
}
